import java.util.Scanner;

public class GuessNumber {
    public static void main(String[] args) {

        //生成一个1-100质检的答案数字
        int answer = (int) (Math.random() * 100 + 1);
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入：");
        int guess = scanner.nextInt();
        //比较答案数字与用户猜测数字关系后打印提示信息的功能，经验证功能正确
        if (guess > answer) {
            System.out.println("大了！");
        } else if (guess < answer) {
            System.out.println("小了");
        } else {
            System.out.println("恭喜你！猜对啦！");
        }

        int chance = 7;
        chance = chance - 1;
        if (chance == 0 && guess == answer) {
            System.out.println("次数用完了！你没有机会啦！");
            System.out.println("游戏结束");
        }

        String again = scanner.next();
        System.out.println("再玩一次吗？（y/n)");
        if (!again.equalsIgnoreCase("y")) {
            return;
        }

    }
}
